#include "hash.h"
/* recieves an id and hash's it to 1~13 */
int H(unsigned x){
	return (x % HASH_TABLE_SIZE);
}

/* this translates an id to a bucket pointer (list pointer)*/
my_list *Hash_table_get_bucket(unsigned id, my_list table[]){
	return ( &(table[H(id)]) );

}

void DS_init(my_list table[]){
	int i=0;

	for( i=0 ; i<HASH_TABLE_SIZE ; ++i){
		initMyList(&table[i]);
	}
}

void DS_free(my_list table[]){
	int i;
	for( i=0 ; i<HASH_TABLE_SIZE ; ++i){
		freeList( &(table[i]) );
	}
}


int DS_insert(unsigned id, char* name, my_list table[]){
	return insertRecord(Hash_table_get_bucket(id,table), id , name);
}

int DS_delete(unsigned id, my_list table[]){
	return deleteRecord(Hash_table_get_bucket(id,table), id);
}

char *DS_get_record(unsigned id, my_list table[]) {
	return retrieveRecord(Hash_table_get_bucket(id,table), id);

}


